package com.ruoyi.web.controller.region;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.region.domain.TSysProvince;
import com.ruoyi.region.service.ITSysProvinceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 省份Controller
 * 
 * @author ruoyi
 * @date 2024-12-14
 */
@RestController
@RequestMapping("/region/province")
public class TSysProvinceController extends BaseController
{
    @Autowired
    private ITSysProvinceService tSysProvinceService;

    /**
     * 查询省份列表
     */
    @PreAuthorize("@ss.hasPermi('region:province:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSysProvince tSysProvince)
    {
        startPage();
        List<TSysProvince> list = tSysProvinceService.selectTSysProvinceList(tSysProvince);
        return getDataTable(list);
    }

    /**
     * 查询省份列表
     */
    @GetMapping("/selectProvinceList")
    public AjaxResult selectProvinceList(TSysProvince tSysProvince)
    {
        List<TSysProvince> list = tSysProvinceService.selectTSysProvinceList(tSysProvince);
        return AjaxResult.success(list);
    }

    /**
     * 导出省份列表
     */
    @PreAuthorize("@ss.hasPermi('region:province:export')")
    @Log(title = "省份", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSysProvince tSysProvince)
    {
        List<TSysProvince> list = tSysProvinceService.selectTSysProvinceList(tSysProvince);
        ExcelUtil<TSysProvince> util = new ExcelUtil<TSysProvince>(TSysProvince.class);
        util.exportExcel(response, list, "省份数据");
    }

    /**
     * 获取省份详细信息
     */
    @PreAuthorize("@ss.hasPermi('region:province:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tSysProvinceService.selectTSysProvinceById(id));
    }

    /**
     * 新增省份
     */
    @PreAuthorize("@ss.hasPermi('region:province:add')")
    @Log(title = "省份", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSysProvince tSysProvince)
    {
        return toAjax(tSysProvinceService.insertTSysProvince(tSysProvince));
    }

    /**
     * 修改省份
     */
    @PreAuthorize("@ss.hasPermi('region:province:edit')")
    @Log(title = "省份", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSysProvince tSysProvince)
    {
        return toAjax(tSysProvinceService.updateTSysProvince(tSysProvince));
    }

    /**
     * 删除省份
     */
    @PreAuthorize("@ss.hasPermi('region:province:remove')")
    @Log(title = "省份", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSysProvinceService.deleteTSysProvinceByIds(ids));
    }
}
